﻿@using System.Data;
@using System.Data.OleDb;
@model string
<style>
    .form-control.ui-queryString option {
        padding: 5px;
    }
</style>
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">附件表管理</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>

<div class="main">
    <ul class="navTabs">
        <li data-tab-params="tabName:'使用中',tabValue:'1',tabValueObjName:'#state'"></li>
        <li data-tab-params="tabName:'已废弃',tabValue:'0',tabValueObjName:'#state'"></li>
    </ul>
    <table border=0 cellpadding=0 cellspacing=0 class="tb-head form-inline form-group-sm">
        <tr>
            <td align="left">
                <button type="button" class="btn btn-default btn-sm" id="ClearAllInvalid" data-toggle="tooltip" data-placement="bottom" title="提交处理时间视冗余数据的大小而定!">一键清理冗余数据</button>
            </td>
            <td align="right">
                <select id="s_type" name="s_type" class="form-control form-control-xs ui-queryString ui-setName">
                    <option value="name">按表名搜索</option>
                    <option value="remark">按备注搜索</option>
                    <option value="parentTable">按所属父级表</option>
                </select>
                <input type="hidden" id="state" name="state" value="1" class="ui-queryString">
                <input type="text" maxlength="30" class="form-control ui-keyword  ui-queryString">
                <input type="button" value="确定" class="btn btn-default btn-sm ui-queryString-search">
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered form-inline form-group-sm" id="tb_list">
        <thead>
            <tr>
                <td align="center" rowspan="2">表名</td>
                <td align="center" rowspan="2">备注</td>
                <td align="center" rowspan="2">父级表</td>
                <td align="center" rowspan="2">父级字段</td>
                <td align="center" rowspan="2">创建日期</td>
                @*<td align="center" rowspan="2">创建人</td>*@
                <td align="center" colspan="3">统计</td>
                <td align="center" rowspan="2">附件管理</td>
            </tr>
            <tr>
                <td align="center">使用中</td>
                <td align="center">未使用</td>
                <td align="center">已删除</td>
            </tr>
        </thead>
        <tr class="item list-template-item" id="item_{id}">
            <td align="center">{name}</td>
            <td align="center">{remark}</td>
            <td align="center">{parentTable}</td>
            <td align="center">{parentField}</td>
            <td align="center"><span class="lb_thedate">{thedate}</span></td>
            @*<td align="center"><span class="lb_uid" data-custom-params="url:'@Url.ActionUrl("GetFieldByIds", "Member")',textField:'username'">{uid}</span></td>*@
            <td align="center"><span class="lb_using loading" table="{name}"></span></td>
            <td align="center"><span class="lb_nousing loading"></span>@*<a href="javascript:void(0)" class="ui-deleteSingle" data-custom-params="url:'@Url.ActionUrl("ClearData","AttachmentDataAdmin")?table={name}&state=0',confirmMsg:'是否确定此操作？',successMsg:'已经提交,请等待处理！',callBack:'null'">[清理]</a>*@</td>
            <td align="center"><span class="lb_deleted loading"></span><a href="javascript:void(0)" class="ui-deleteSingle" data-custom-params="url:'@Url.ActionUrl("ClearData","AttachmentDataAdmin")?table={name}&state=-1',confirmMsg:'是否确定此操作？',successMsg:'已经提交,请等待处理！',callBack:'null'">[清理]</a></td>
            <td align="center">
                <button type="button" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'{remark}-附件管理',url:'@Url.ActionUrl("Index","AttachmentDataAdmin")?table={name}',width:'95%',height:'95%'">管理</button>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    $(".navTabs").children().InitTab(function () { LoadData() }); //初始化选项卡，并设置回调函数为LoadData()


    function LoadData() {
        var ajaxUrl = "@Url.ActionUrl("PageListData")";
        $("#tb_list").ListBind({url:ajaxUrl,callBack: "LoadedInit" });
    }
    function LoadedInit()
    {
        $(".deleteBtn_1").attr("disabled", "disabled");
        var $lb_thedate = $(".lb_thedate");
        $lb_thedate.each(function () {
            var $this = $(this);
            $this.html($this.html().split(" ")[0]);
        })
        //ConvertText($(".lb_uid"));
        var $lb_deleted = $(".lb_deleted");
        var $lb_nousing = $(".lb_nousing");
        var $lb_using = $(".lb_using");

        $lb_using.each(function (i) {
            var $this = $(this);
            var table = $this.attr("table");
            Ajax({type:"get",async:true,url:"@Url.ActionUrl("Count", "AttachmentDataAdmin")", data: "table=" + table }, function (data) {
                if (data != "") {
                    $lb_deleted.eq(i).removeClass("loading").html(data.deletedNums);
                    $lb_nousing.eq(i).removeClass("loading").html(data.nousingNums);
                    $this.removeClass("loading").html(data.usingNums);
                }
            });
        });
    }
    LoadData();

    $(function () { $("[data-toggle='tooltip']").tooltip(); });
    $("#ClearAllInvalid").on("click", function () {
        Loading();
        Ajax({ type: "post",url:"@Url.ActionUrl("ClearAllInvalid")" }, function (data)
        {
            Msg("已提交,后台正在处理中!");
            CloseLoading();
         });
    });
</script>
